using System;
using System.Linq.Expressions;
using System.Reflection;
using Magiq.Update;

namespace Magiq.Sql {
    public class InsertPropertyAssignment : IPropertyValueAssignment {
        private readonly PropertyInfo propertyInfo;

        public InsertPropertyAssignment(PropertyInfo propertyInfo, LambdaExpression value) {
            this.propertyInfo = propertyInfo;
            ValueExpression = value;
        }

        #region IPropertyValueAssignment Members

        public LambdaExpression ValueExpression { get; private set; }

        public string PropertyName {
            get { return propertyInfo.Name; }
        }

        public Type ValueType {
            get { return PropertyType; }
        }

        public Type PropertyType {
            get { return propertyInfo.PropertyType; }
        }

        #endregion

        public override string ToString() {
            return PropertyName + " = " + ValueExpression.Body;
        }
    }
}